<?php
require_once('include/permiss.php');
require_once('include/header.php');
require_once('include/menu.php');
require_once('config.php');
?>
<div class="container">
    <div class="box">
        <div class="box-heading">ĐƠN HÀNG</div>
        <div class="box-content">
            <form method="post" action="#">
                <table class="list">
                    <tr bgcolor="#EFEFEF">
                        <th class="image">Đơn hàng</th>
                        <th class="name">Thực khách</th>
                        <th class="quantity">Số lượng món</th>
                        <th class="quantity">Thời gian đặt</th>
                        <th class="quantity">Trạng thái</th>
                        <th class="action">Thao tác</th>
                    </tr>
                    <?php
                    $pdo = $conn->prepare('SELECT datab_order.*, count(id) as soluongmon FROM datab_order JOIN datab_order_product ON datab_order.order_id=datab_order_product.order_id GROUP BY datab_order.order_id');
                    $pdo->execute();
                    if ($pdo->rowCount()) {
                        $data = $pdo->fetchAll();
                        foreach ($data as $row) {
                            ?>
                            <tr>
                                <td class="image">#<?php echo $row['order_id']; ?></td>
                                <td class="name"><?php echo $row['customer_name']; ?></td>
                                <td class="quantity"><?php echo $row['soluongmon']; ?></td>
                                <td class="quantity"><?php echo $row['order_time']; ?></td>
                                <td class="quantity">
                                    <?php
                                    if ($row['order_status'] == 0) {
                                        echo '<font style=\'color:red;\'>Chờ xử lý</font>';
                                    } elseif ($row['order_status'] == 1) {
                                        echo 'Đang xử lý';
                                    } elseif ($row['order_status'] == 2) {
                                        echo '<font style=\'color:blue;\'>Hoàn thành</font>';
                                    }
                                    ?>
                                </td>
                                <td class="action">
                                    <a class='ajax' href="editorder.php?order_id=<?php echo $row['order_id'] . "&token=" . $_SESSION['token']; ?>">[Xem]</a>
                                    <a href='javascript:void(0);' onclick= onDel("delorder.php?action=del&order_id=<?php echo $row['order_id'] . "&token=" . $_SESSION['token']; ?>")>[Xóa]</a>
                                    <a class='ajax' href="optionstatus.php?order_id=<?php echo $row['order_id'] . "&token=" . $_SESSION['token']; ?>">[Trạng thái]</a>
                                    <a href="export.php?order_id=<?php echo $row['order_id'] . "&token=" . $_SESSION['token']; ?>">[Xuất hóa đơn]</a>
                                </td>
                            </tr>
                            <?php
                        }
                    }
                    ?>                        
                </table>
            </form>
        </div>
    </div>    
</div>
<?php
require_once('include/footer.php');
?>
 
